#include "enemyplane.h"

EnemyPlane::EnemyPlane()
{
    //敌机资源加载
    m_enemy.load(ENEMY_PATH);
    //敌机位置
    m_X = 0;
    m_Y = 0;
    //敌机状态
    m_Free = true;
    //敌机速度
    m_Speed = ENEMY_SPEED;
    //敌机矩形
    m_Rect.setWidth(m_enemy.width());
    m_Rect.setHeight(m_enemy.height());
    m_Rect.moveTo(m_X,m_Y);
    //敌机血量
    m_Blood=ENEMY_BLOOD;

}
void EnemyPlane::updatePosition()
{
    //空闲状态，不计算坐标
    if(m_Free)
    {
        return;
    }
    m_Y += m_Speed;
    m_Rect.moveTo(m_X,m_Y);
    if(m_Y >= GAME_HEIGHT)
    {
        m_Free = true;
        m_Blood=ENEMY_BLOOD;
    }
}
void EnemyPlane::shoot()
{
    //累加时间间隔
     m_recorder++;
     //如果记录的数字未达到发射子弹的时间间隔，不发射子弹
     if(m_recorder<ENEMY_BULLET_INTERVAL)
     {
         return;
     }
     //达到发射时间
     m_recorder=0;
     //发射子弹
     for(int i=0;i<ENEMY_BULLET_NUM;i++)
     {
         //如果是空闲子弹 进行发射
         if(enemy_bullets[i].m_Free)//第二行，第三行都跟第一行
         {
             enemy_bullets[i].m_Free=0;
             enemy_bullets[i].m_x=m_X+40;
             enemy_bullets[i].m_y=m_Y+40;
             break;
         }
     }

}
